<?php
/**
 * Created by PhpStorm.
 * User: alice
 * Date: 2015/12/26
 * Time: 14:14
 */

/**
 * Class Involved_BankManageModel
 */

class Involved_BankManageModel extends BaseModel
{

    protected $table = 'bank_manage';

    /**
     * 获取银行卡列表
     */
    public function BankManageList(){
        return  DB::table($this->table)
            ->selectRaw('ypt_bank_manage.bank_id,ypt_bank_manage.bank_name,ypt_bank_manage.bank_num,ypt_bank_manage.created,ypt_bank_manage.status,ypt_user.user_name as user_id')
            ->leftjoin('user','bank_manage.user_id','=','user.user_id')
            ->get();
    }

    /**
     * 获取银行卡
     */
    public function GetBankManageOne($user_id){
        return  DB::table($this->table)
            ->where(['bank_manage.user_id'=>$user_id])
            ->first();
    }
    /**
     * 判断银行卡是否已经绑定
     */
    public function GetBankManageyeno($user_id){
        return  DB::table($this->table)
            ->where(['bank_manage.user_id'=>$user_id])
            ->count('bank_manage.bank_id');
    }

    /**
     * 个人中心银行卡列表
     * @param $user_id
     * @return mixed
     */
    public function UserBankcard($user_id)
    {
        return DB::table($this->table)
            ->where('bank_manage.user_id',$user_id)
            ->get();
    }

    /**
     * 银行卡编辑
     * @param $bank_id
     * @return mixed
     */
    public function UserBankcardUp($bank_id)
    {
        return DB::table($this->table)
            ->where('bank_id',$bank_id)
            ->first();
    }

    /**
     * app绑定银行卡信息返回
     * @param $user_id
     * @return mixed
     */
    public function SelUserBank($user_id)
    {
        $bank =  DB::table($this->table)
            ->select('bank_manage.user_id','bank_name','bank_num','bound_name','kaihuhang','bound_mobile','created','province','city','area','bank_manage.status','bank_code')
            ->where(['user_id'=>$user_id])
            ->first();

        return $bank;
    }

    /**
     * app绑定银行卡信息返回
     * @param $user_id
     * @return mixed
     */
    public function BankInfo($user_id)
    {
        $bank =  DB::table($this->table)
            ->select('bank_name','bank_num','bound_name','kaihuhang','bound_mobile','created','province','city','area','user_balance','bank_manage.status','logo','bank_code')
            ->join('user_extend','user_extend.user_id' ,'=','bank_manage.user_id')
            ->where(['bank_manage.user_id'=>$user_id])
            ->first();

        return $bank;
    }

//    /**
//     * app修改银行卡信息返回
//     * @param $user_id
//     * @return mixed
//     */
//    public function BankUpInfo($user_id)
//    {
//        $bank =  DB::table($this->table)
//            ->select('bank_name','bank_num','bound_name','kaihuhang','bound_mobile','bank_manage.created','province','city','area','user_balance','bank_manage.status')
//            ->join('user_extend','user_extend.user_id' ,'=','bank_manage.user_id')
//            ->join('user','user.user_id' ,'=','bank_manage.user_id')
//            ->where(['bank_manage.user_id'=>$user_id])
//            ->first();
//
//        return $bank;
//    }
}